1. Field
One or more embodiments of the present invention relate to a method, medium, and apparatus for improving the speed of context switching and, more particularly, to a method, medium and apparatus for storing and restoring a register context for fast context switching between tasks.
2. Description of the Related Art
A context switch is a computing technique for storing and restoring the state (context) of a CPU, or other device, such that multiple processes can share a single CPU resource. A context switch enables a CPU to perform multiple tasks by switching a context that is a working environment of tasks when the multiple tasks operate in a system. The context is a set of task resources managed by a kernel and execution environments. A context switch is typically an essential feature of a multitasking operating system.
Not only a general system such as a computer and a notebook computer but also a real time operating system (RTOS) of an embedded system such as ARM® and StarCore™ DSP require a context switch for supporting multitasking. Several kinds of information may be included in the context, and particularly, lots of register contexts may be required. An ARM® system has 16 general purpose data registers of 32 bits, and the StarCore™ DSP includes 16 general data registers of 40 bits, 16 general address registers of 32 bits, four offset registers of 32 bits, four modulo registers of 32 bits, four start registers of 32 bits, and four loop counter registers of 32 bits.
In an embedded system such as DSP, the number of registers is increased in order to improve performance, and this causes the number of registers for context storage during context switching to also be increased. Fast context switching is the core of the RTOS performance. However, context switching time is proportional to the number of registers for storing and restoring the contexts. Thus, an increased number of registers will increase contact switching time and accordingly affect RTOS performance.
FIG. 1 illustrates a conventional context switching process, in which context switching is performed between two tasks. Determining whether a task is currently running may be accomplished through a task control block (TCB). In the conventional context switching process, all register contexts are stored in a previous task stack 11, and then a register context of a new task to be run is restored in a new task stack 12. However, if the number of registers becomes large, the size of the register contexts to be stored in the previous task stack 11 and the register contexts to be restored in the new task stack 12 may become excessive. For example, in the StarCore™ system, at least 208 bytes are required. Accordingly, it may impede fast context switching to increase the number of registers in order to increase the performance of the system, and this may in turn disturb the improvement of the system performance.
A register relocation method has also been proposed. Here, register files are partitioned by tasks in advance, and thus no register switch is required during task context switching. However, this method requires large-sized register files, and the number of tasks should be limited in order to obtain a hardware effect. Also, since the entire contexts to be used by tasks are statically determined, it is difficult to apply the method to a dynamic system.
Consequently, a method, medium, and apparatus, which can perform fast context switching even in a system having a plurality of registers, or in a situation where tasks are dynamically created, is desired.